//
//  TSSettingViewController.m
//  TSListDemo
//
//  Created by qian on 2020/11/19.
//  Copyright © 2020 dvlproad. All rights reserved.
//

#import "TSSettingViewController.h"
#import <Masonry/Masonry.h>
#import "CQTitleResultTableViewCell.h"
#import "CQTitleSwitchTableViewCell.h"
#import "CQTitleInputTableViewCell.h"

@interface TSSettingViewController () <UITableViewDataSource, UITableViewDelegate> {
    
}

@end

@implementation TSSettingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self setupViews];
}

- (void)setupViews {
    UITableView *tableView = [[UITableView alloc] init];
    [tableView registerClass:[CQTitleResultTableViewCell class] forCellReuseIdentifier:@"CQTitleResultTableViewCell"];
    [tableView registerClass:[CQTitleSwitchTableViewCell class] forCellReuseIdentifier:@"CQTitleSwitchTableViewCell"];
    [tableView registerClass:[CQTitleInputTableViewCell class] forCellReuseIdentifier:@"CQTitleInputTableViewCell"];
    tableView.dataSource = self;
    tableView.delegate = self;
    [self.view addSubview:tableView];
    [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(self.view);
    }];
}


#pragma mark - UITableViewDataSource & UITableViewDelegate

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    NSInteger iRowCount = 5;
    return iRowCount;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 44;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.item == 1) {
        CQTitleSwitchTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CQTitleSwitchTableViewCell" forIndexPath:indexPath];
        cell.title = @"通知权限";
        cell.swthOn = NO;
        return cell;
    } else {
        CQTitleResultTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CQTitleResultTableViewCell" forIndexPath:indexPath];
        if (indexPath == 0) {
            cell.title = NSLocalizedString(@"账号设置", nil);
            cell.result = nil;
            cell.clickHandle = ^(NSString * _Nonnull title) {
                NSLog(@"点击了%@", title);
            };
        } else if (indexPath.item == 2) {
            cell.title = NSLocalizedString(@"群聊名称", nil);
            cell.result = @"3.15MB";
            cell.clickHandle = ^(NSString * _Nonnull title) {
                NSLog(@"点击了%@", title);
            };
        } else if (indexPath.item == 3) {
            cell.title = NSLocalizedString(@"关于表里", nil);
            cell.result = nil;
            cell.clickHandle = ^(NSString * _Nonnull title) {
                NSLog(@"点击了%@", title);
            };
        } else {
            cell.title = NSLocalizedString(@"退出登录", nil);
            cell.result = nil;
            cell.clickHandle = ^(NSString * _Nonnull title) {
                NSLog(@"点击了%@", title);
            };
        }
        
        return cell;
    }
}

#pragma mark - UITableViewDelegate

- (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.item == 1) {
        return NO;  // 禁止高亮
    }
    return YES;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    UITableViewCell *cell =  [tableView cellForRowAtIndexPath:indexPath];
    if ([cell isKindOfClass:[CQTitleResultTableViewCell class]]) {
        CQTitleResultTableViewCell *titleResultCell = (CQTitleResultTableViewCell *)cell;
        !titleResultCell.clickHandle ?: titleResultCell.clickHandle(titleResultCell.title);
    }
}



#pragma mark - Touch
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    [super touchesBegan:touches withEvent:event];
}



/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
